#include <windows.h>
#include <stdio.h>

struct student {
    char *name;
    int num;
    int age;
    char sex;
    float score;
} stus[5] = {
        {"1", 1, 1, 'M', 1.1f},
        {"2", 2, 2, 'M', 2.1f},
        {"3", 3, 3, 'M', 3.1f},
        {"4", 4, 4, 'M', 4.1f},
        {"5", 5, 5, 'M', 5.1f}
};

void fun(struct student *p, int a);

int main() {
    SetConsoleOutputCP(65001);

    struct student *p;
    int i;
    p = stus; // 将结构体数组首地址赋予结构体指针
    printf("姓名\t学号\t年龄\t性别\t成绩\t\n");
    for (i = 0; i < 5; i++) {
        // (*p).age
        // p->age
        printf("%s\t%d\t%d\t%c\t%.1f\n",
                (p+i)->name, (p+i)->num, (p+i)->age, (p+i)->sex, (p+i)->score);
    }
    fun(p, 5);
    return 0;
}

void fun(struct student *p, int a) {
    int num_3 = 0;
    float sum = 0.0f;
    int i;
    for (i = 0; i < a; i++) {
        sum += (p + i)->score;
        if ((p + i)->score < 3.1) {
            num_3++;
        }
    }
    printf("总成绩 num=%.2f\n平均成绩 average=%.2f\n不及格人数 num_3=%d\n",
           sum, sum / 5, num_3);
}
